<template>
	<view class="page">
		<view class="title"> 基本信息 </view>
		<view class="info">
			<view>
				<view class="item-title"> 客户名称 </view>
				<view class="item-content">
					<u-tag :text="recordInfo.customerName" mode="plain" type="primary" @click="toShowMessage(recordInfo, 'customer')"></u-tag>
				</view>
			</view>
			<view>
				<view class="item-title"> 联系人 </view>
				<view class="item-content">
					<u-tag style="margin-right: 10rpx" :text="contact.name" mode="plain" type="primary" v-for="(contact, index) in recordInfo.contactsList" :key="index" @click="toShowMessage(contact, 'contacts')"></u-tag>
				</view>
			</view>
			<!-- <view v-if="recordInfo.businessList && recordInfo.businessList.length">
                <view class="item-title">
                    关联商机
                </view>
                <view class="item-content">
                    <u-tag style="margin-right: 10rpx;" :text="business.businessName" mode="plain"
                        type="primary" v-for="(business,index) in recordInfo.businessList" :key="index" @click="toShowMessage(business,'business')"></u-tag>
                </view>
            </view> -->
			<view>
				<view class="item-title"> 跟进方式 </view>
				<view class="item-content">
					<text>{{ recordInfo.category }}</text>
				</view>
			</view>
		</view>
		<view class="title"> 跟进更新信息 </view>
		<view class="info">
			<view v-for="(content, index) in recordContentFields" :key="index">
				<view class="item-title">
					{{ content.value }}
				</view>
				<view class="item-content">
					<text>{{ recordInfo[content.name] ? recordInfo[content.name] : '--' }}</text>
				</view>
			</view>
			<view>
				<view class="item-title"> 附件 </view>
				<view class="item-content">
					<view class="item-file" v-for="(file, index) in recordInfo.file" :key="index" @click="checkFile(recordInfo.file, index)">
						<text>{{ file.name }}</text>
					</view>
				</view>
			</view>
			<view>
				<view class="item-title"> 下次联系时间 </view>
				<view class="item-content">
					<text>{{ recordInfo.nextTime ? recordInfo.nextTime : '--' }}</text>
				</view>
			</view>
		</view>
		<view class="title"> 系统信息 </view>
		<view class="info">
			<view>
				<view class="item-title"> 创建人 </view>
				<view class="item-content">
					<text>{{ recordInfo.realname }}</text>
				</view>
			</view>
			<view>
				<view class="item-title"> 创建时间 </view>
				<view class="item-content">
					<text>{{ recordInfo.createTime }}</text>
				</view>
			</view>
		</view>
		<l-file ref="lFile"></l-file>
	</view>
</template>

<script>
import { queryFollowRecordByIdAPI, queryFollowRecordContentFieldsAPI } from '@/api/customer/common.js';

import lFile from '@/components/l-file/l-file.vue';
export default {
	data() {
		return {
			recordId: null,
			recordInfo: {},
			recordContentFields: [],
		};
	},
	components: {
		lFile,
	},
	onLoad(option) {
		this.getFollowRecordContentFields();
		this.recordId = option.recordId;
		this.getFollowRecord();
	},
	methods: {
		getFollowRecord() {
			let param = {
				recordId: this.recordId,
			};
			queryFollowRecordByIdAPI(param).then((res) => {
				this.recordInfo = res.data;
			});
		},
		getFollowRecordContentFields() {
			queryFollowRecordContentFieldsAPI().then((res) => {
				this.recordContentFields = res.data.list;
			});
		},
		checkFile(files, index) {
			let urls = files.map((item) => {
				return item.filePath;
			});
			let fileType = files[index].fileType;
			this.$refs.lFile.showFile(urls, index, fileType);
		},

		toShowMessage(item, type) {
			let params = {};
			params = {
				crmId: item[type + 'Id'],
				crmType: type,
			};
			uni.navigateTo({
				url: '/pages/customerManagement/common/CrmBaseInfo?params=' + encodeURIComponent(JSON.stringify(params)),
			});
		},
	},
};
</script>

<style>
.page {
	width: 100%;
	height: 100%;
	overflow: auto;
}

.title {
	padding: 20px 15px 10px;
	font-size: 16px;
}

.info {
	background: #fff;
	/* margin-bottom: 20px; */
	padding: 15px;
}

.info .item-title {
	font-weight: bold;
}

.info .item-content {
	display: flex;
	flex-wrap: wrap;
	width: calc(100%-30px);
	box-sizing: border-box;
	padding: 10rpx 0 10rpx 56rpx;
}

.info .item-file {
	background-color: #eee;
	color: #007aff;
	margin-bottom: 5rpx;
}

.info .item-file:active {
	background-color: #007aff;
	color: #ffffff;
}
</style>
